def str_reverse1(s):
    return s[::-1]

class Solution:
    
    def longestPalindrome(self, s: str) -> str:
        length = len(s)
        max_len = 0
        max_str = ""
        for i in range(length):
            min_j = min(i,length-i)
            for j in range(0,min_j+1):
                # print(s[i:i+j+1]," ",str_reverse1(s[i-j:i+1]))
                if(s[i:i+j+1] != str_reverse1(s[i-j:i+1])):
                    break

                if max_len < (2*j+1):
                    st = s[i:i+j+1]
                    max_str = st[::-1] + st[1:]  
                    max_len = (2*j+1)

            min_j = min(i,length-i-1)
            for j in range(min_j+1):
                # print(s[i+1:i+j+2]," ",str_reverse1(s[i-j:i+1]))
                if(s[i+1:i+j+2] != str_reverse1(s[i-j:i+1])):
                    break
                if max_len < 2*(j+1):
                    st = s[i+1:i+j+2]
                    max_str = st[::-1] + st[:]  
                    max_len = 2*(j+1)
        # print(max_len)
        return max_str

# if __name__ == "__main__":
#     st = "112345654321"
#     s = Solution()
#     res = s.longestPalindrome(st)
#     print(res)   

